/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.meshview.state;

import java.awt.event.MouseEvent;
import jinngine.math.Quaternion;

/**
 *
 * @author Pierre
 */
class ZoomState extends AbstractState {

    private final static double ZOOM_SENSIBILITY = .005;
    final int oldy;
    final double oldDistance;
    final MeshCamera camera;
    final Quaternion light;

    ZoomState(MeshCamera camera, Quaternion light, MouseEvent e) {
        oldy = e.getY();
        oldDistance = camera.currentDistance;
        this.camera = camera;
        this.light=light;
    }

    @Override
    public AbstractState mouseDragged(MouseEvent e) {
        camera.currentDistance = oldDistance * Math.exp((oldy - e.getY()) * ZOOM_SENSIBILITY);
        redraw(e);
        return this;
    }

    @Override
    public AbstractState mouseReleased(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            return new DefaultState(camera,light);
        }
        return this;
    }
}
